<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <div class="text-desc">已与处置方核实确认成交？</div>
      <el-form ref="form" size="mini" :model="form" label-width="0" label-position="top">
        <el-form-item prop="record_id" label="选择成交会员:" required="">
          <el-radio-group v-model="form.record_id">
            <el-radio v-for="item in phoneList" :key="item.id" :label="item.id">{{ item.vip_name }}({{ item.vip_phone }})</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item style="margin-bottom: 0; margin-top: 40px">
          <div class="panel-line flex-end">
            <el-button @click="onCancel">取消</el-button>
            <el-button :loading="loading" type="primary" @click="onSubmit">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { apiNoShareWaitDeal, apiNoShareDealConfirm } from '@/api/assetsAlone'

export default {
  name: 'DialogDeal',
  props: {
    id: String,
  },
  data() {
    return {
      loading: false,
      phoneList: [],
      form: {
        sts: 2,
        record_id: '',
      },
    }
  },
  mounted() {
    this.init()
  },
  destroyed() {},
  methods: {
    init() {
      // 获取标记过成交的手机号
      apiNoShareWaitDeal({ id: this.id }).then((res) => {
        const { data } = res
        this.phoneList = data
      })
    },
    // 取消
    onCancel() {
      this.$emit('close')
    },
    // 确定
    onSubmit() {
      if (this.form.record_id === '') {
        this.$message({
          type: 'error',
          message: '选择成交会员',
        })
        return
      }
      this.form.id = this.id
      this.loading = true
      apiNoShareDealConfirm(this.form)
        .then((res) => {
          this.$message({
            message: '操作成功',
            type: 'success',
          })
          setTimeout(() => {
            this.loading = false
            this.$emit('success')
          }, 1000)
        })
        .catch(() => {
          this.loading = false
        })
    },
  },
}
</script>

<style scoped lang="scss">
.text-desc {
  width: 100%;
  padding: 10px 16px;
  background: #fef3e4;
  margin-bottom: 30px;
}
</style>
